/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */

var combinationSum2 = function (candidates, target) {
    // 结果数组
    let res = []
    // 运营数组
    let arr = []
    let len = candidates.length
    candidates.sort((a, b) => a - b)
    backtrack(0, 0)
    return res
    function backtrack(index, sum) {
        // 终止条件
        if (sum > target) {
            return
        }
        // 终止条件
        if (sum === target) { 
            res.push(arr.slice())
        }
        let f = -1
        for (let i = index; i < len; i++) {
            if (candidates[i] === f) {
                continue
            }
            f = candidates[i]
            arr.push(candidates[i])
            sum += candidates[i]
            backtrack(i + 1, sum)
            arr.pop()
            sum -= candidates[i]
        }
    }
};